<link href="asset/css/show.css" rel="stylesheet" type="text/css">
<script src="asset/js/cetak_excel.js"></script>
<script src="module/mod_penyakit/js/combo.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("#periode").change(function(){
		var periode = $("#periode").val();
		if(periode == 1){
			document.getElementById('tgl1').disabled = false;
			document.getElementById('tgl2').disabled = false;
			document.getElementById('bln1').disabled = false;
			document.getElementById('bln2').disabled = false;
		}
		else if(periode == 2){
			document.getElementById('tgl1').disabled = true;
			document.getElementById('tgl2').disabled = true;
			document.getElementById('bln1').disabled = false;
			document.getElementById('bln2').disabled = false;
		}else{
			document.getElementById('tgl1').disabled = true;
			document.getElementById('tgl2').disabled = true;
			document.getElementById('bln1').disabled = true;
			document.getElementById('bln2').disabled = true;
		}
	});
});
</script>
<?php
	$tgl = date("d");
	$bln = date("m");
	$thn = date("Y");
	
	$periode = $_POST['periode'];
	$tgl1 = $_POST['tgl1'];
	$tgl2 = $_POST['tgl2'];
	$bln1 = $_POST['bln1'];
	$bln2 = $_POST['bln2'];
	$thn1 = $_POST['thn1'];
	$thn2 = $_POST['thn2'];
	
	$rs = $_POST['ppk'];
	$jns_kelamin = $_POST['jk'];
	$usia = $_POST['umur'];
	$kerja = $_POST['pekerjaan'];
	$wlyh = $_POST['kecamatan'];
	$agm = $_POST['agama'];
	$st = $_POST['status'];
	$ds = $_POST['desa'];
?>
<div id="tiga_ba">
	<div id="tiga_baa">Statistik 10 Besar Penyakit RJTL </div>
	<div id="tiga_bab">
		
	</div>
	<div class="clear"></div>
</div>

<form method="post" action='utama.php?module=mod_penyakit&view=rjtl'>
	<table style="margin-left: 5px;">
		<tr>
			<td>Periode</td>
			<td>
				<select name="periode" id="periode" class="input1">
					<?php
						if($periode == 1){
							$s1 = "selected";
						}else if($periode == 2){
							$p1 = "disabled";
							$s2 = "selected";
						}else{
							$p1 = "disabled";
							$p2 = "disabled";
							$s3 = "selected";
						}
					?>
					<option value="1" <?php echo $s1; ?>>Hari</option>
					<option value="2" <?php echo $s2; ?>>Bulan</option>
					<option value="3" <?php echo $s3; ?>>Tahun</option>
				</select>
			</td>
			<td>Umur</td>
			<td>
				<select name="umur" class="input2">
					<option value=""> - - Pilih Semua - - </option>
					<?php
						$umur= mysql_query("select * from umur");
						while($u = mysql_fetch_array($umur)){
							if($u['id_umur'] == $usia){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value='$u[id_umur]' $s>$u[umur]</option>";
						}
					?>
				</select>
			</td>
		</tr>
		<tr>
			<td>Dari</td>
			<td>
				<select name="tgl1" id="tgl1" class="input1" <?php echo $p1; ?>>
					<option value="">Tgl</option>
					<?php
						for($i=1;$i<=31;$i++){
							if($i == $tgl && $tgl1 == ''){
								$s = "selected";
							}else if($i == $tgl1){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
				<select name="bln1" id="bln1" class="input1" <?php echo $p2; ?>>
					<option value="">Bln</option>
					<?php
						for($i=1;$i<=12;$i++){
							if($i == $bln && $bln1 == ''){
								$s = "selected";
							}else if($i == $bln1){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
				<select name="thn1" id="thn1" class="input1">
					<option value="">Thn</option>
					<?php
						for($i=2010;$i<=2020;$i++){
							if($i == $thn && $thn1 == ''){
								$s = "selected";
							}else if($i == $thn1){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
			</td>
			<td>Pekerjaan</td>
			<td>
				<select name="pekerjaan" class="input2">
					<option value=""> - - Pilih Semua - - </option>
					<?php
						$pekerjaan= mysql_query("select * from pekerjaan");
						while($p = mysql_fetch_array($pekerjaan)){
							if($p['id_pekerjaan'] == $kerja){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value='$p[id_pekerjaan]' $s>$p[pekerjaan]</option>";
						}
					?>
				</select>
			</td>
		</tr>
		<tr>
			<td>Sampai</td>
			<td>
				<select name="tgl2" id="tgl2" class="input1" <?php echo $p1; ?>>
					<option value="">Tgl</option>
					<?php
						for($i=1;$i<=31;$i++){
							if($i == $tgl && $tgl2 == ''){
								$s = "selected";
							}else if($i == $tgl2){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
				<select name="bln2" id="bln2" class="input1" <?php echo $p2; ?>>
					<option value="">Bln</option>
					<?php
						for($i=1;$i<=12;$i++){
							if($i == $bln && $bln2 == ''){
								$s = "selected";
							}else if($i == $bln2){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
				<select name="thn2" id="thn2" class="input1">
					<option value="">Thn</option>
					<?php
						for($i=2010;$i<=2020;$i++){
							if($i == $thn && $thn2 == ''){
								$s = "selected";
							}else if($i == $thn2){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
			</td>
			<td>Agama</td>
			<td>
				<select name="agama" class="input2">
					<option value=""> - - Pilih Semua - - </option>
					<?php
						$agama = mysql_query("select * from agama order by id_agama");
						while($a = mysql_fetch_array($agama)){
							if($a['id_agama'] == $agm){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value='$a[id_agama]' $s>$a[agama]</option>";
						}
					?>
				</select>
			</td>
		</tr>
		<tr>
			<?php
				if($_SESSION['id_ppk'] == 0){
			?>
			<td>PPK</td>
			<td>
				<select name="ppk" id="ppk" class="input2">
					<option value=""> - - Pilih Semua - - </option>
					<?php
						$ppk = mysql_query("select id_ppk,nama from ppk order by nama");
						while($p = mysql_fetch_array($ppk)){
							if($rs == $p['id_ppk']){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$p[id_ppk] $s>$p[nama]</option>";
						}
					?>
				</select>
			</td>
			<?php
				}else{
					$ppk = mysql_query("select id_ppk,nama from ppk where id_ppk = $_SESSION[id_ppk]");
					$p = mysql_fetch_array($ppk);
					echo "<td>PPK</td>
						<td>
							<input type=hidden name=ppk id=ppk class=input2 value=$p[id_ppk]>
							$p[nama]
						</td>";
				}
			?>
			<td width="100">Wilayah</td>
			<td width="300">
				<select name="kecamatan" id="kecamatan" class="input2">
					<option value=""> - - Pilih Semua - - </option>
					<?php
						$kecamatan = mysql_query("select * from kecamatan kc inner join kabupaten kb on kc.id_kabupaten = kb.id_kabupaten inner join propinsi p on p.id_propinsi = kb.id_propinsi where kb.aktif = 'Y' and p.aktif = 'Y' order by kecamatan");
						while($k = mysql_fetch_array($kecamatan)){
							if($k['id_kecamatan'] == $wlyh){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value='$k[id_kecamatan]' $s>$k[kecamatan]</option>";
						}
					?>
				</select>
			</td>
		</tr>
		<tr>
			<td width="100">Status Nikah</td>
			<td width="300">
				<select name="status" class="input2">
					<option value=""> - - Pilih Semua - - </option>
					<?php
						$status = mysql_query("select * from status_nikah order by id_status");
						while($n = mysql_fetch_array($status)){
							if($n['id_status'] == $st){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value='$n[id_status]' $s>$n[status_nikah]</option>";
						}
					?>
				</select>
			</td>
			<td colspan="2">
				<span id="sl_desa">
					<?php
						if($wlyh != ''){
						echo "<table>
								<tr>
									<td width=95>Desa</td>
									<td>
										<select name='desa' id='desa' class='input2'>
											<option value='' selected> - - Pilih Semua - - </option>";
											$desa = mysql_query("select * from desa where id_kecamatan = '$wlyh'");
											while($d = mysql_fetch_array($desa)){
												if($d['id_desa'] == $ds){
													$s = "selected";
												}else{
													$s = "";
												}
												echo "<option value='$d[id_desa]' $s>$d[desa]</option>";
											}
										echo "</select>
									</td>
								</tr>
							</table>";
						}else{
										
						}
					?>
				</span>
			</td>
		</tr>
		<tr>
			<td></td>
			<td><input name="submit" id="proses" type="submit" class="button" value="Proses" /></td>
			<td></td>
			<td></td>
		</tr>
	</table>
</form>
<?php
	if(isset($_POST['submit'])){
		if($periode == 1){
			$tgl1 = "and kl.tgl_trans >= '$thn1-$bln1-$tgl1'";
			$tgl2 = "and kl.tgl_trans <= '$thn2-$bln2-$tgl2'";
		}else if($periode == 2){
			$tgl1 = "and kl.tgl_trans >= '$thn1-$bln1-01'";
			$tgl2 = "and kl.tgl_trans <= '$thn2-$bln2-31'";
		}else{
			$tgl1 = "and kl.tgl_trans >= '$thn1-01-01'";
			$tgl2 = "and kl.tgl_trans <= '$thn2-12-31'";
		}

		if($rs != ''){
			$dt_rs = "and kl.id_ppk = $rs";
		}else{
			$dt_rs = "";
		}
		
		if($usia != ''){
			$q_umur = mysql_fetch_array(mysql_query("select * from umur where id_umur = $usia"));
			$dari = $q_umur['dari'];
			$sampai = $q_umur['sampai'];
			$q_usia1 = "and umur >= $dari";
			$q_usia2 = "and umur <= $sampai";
		}else{
		
		}
		
		if($kerja != ''){
			$dt_krj = "and pn.id_pekerjaan = $kerja";
		}else{
			$dt_krj = "";
		}
		
		if($wlyh != ''){
			$dt_wlyh = "and kc.id_kecamatan = '$wlyh'";
		}else{
			$dt_wlyh = "";
		}
		
		if($ds != ''){
			$dt_ds = "and d.id_desa = '$ds'";
			$dt_wlyh = "";
		}else{
			$dt_ds = "";
		}
		
		if($agm != ''){
			$dt_agama = "and pn.id_agama = '$agm'";
		}else{
			$dt_agama = "";
		}
		
		if($st != ''){
			$dt_status = "and pn.id_status = '$st'";
		}else{
			$dt_status = "";
		}

	$query = "select a.icd10, a.nama,datediff(kl.tgl_trans,pn.tgl_lahir) as umur from master_diagnosis a inner join klaim_diagnosis kd on kd.icd10 = a.icd10 inner join klaim kl on kl.id_klaim = kd.id_klaim inner join peserta p on kl.id_peserta = p.id_peserta INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk INNER JOIN keluarga k ON k.id_kk = pn.id_kk inner join desa d on k.id_desa = d.id_desa inner join kecamatan kc on d.id_kecamatan = kc.id_kecamatan inner join kabupaten kb on kc.id_kabupaten = kb.id_kabupaten inner join jenis_layanan jl on kl.id_jenis_layanan = jl.id_jenis_layanan where kb.aktif = 'Y' and jl.kode = '1' $tgl1 $tgl2 $dt_rs $dt_krj $dt_wlyh $q_usia1 $q_usia2 $dt_agama $dt_status $dt_ds group by a.icd10 desc limit 10";
	//echo $query;
	$qry = mysql_query($query);
	?>
		<div id="btnChart">
			<span id="print">
				<a href="#" class="export">
					<img src="asset/images/print.png" width="30">
				</a>
			</span>
		</div>
		<div id="dvData">
		<table class="tabel">
			<tr>
				<th rowspan="2" width="30">NO</th>
				<th rowspan="2" width="50">Kode</th>
				<th rowspan="2">Nama Penyakit</th>
				<th colspan="2">Kasus</th>
				<th rowspan="2" width="75">Total Kasus</th>
				<th rowspan="2" width="75">Total Kunjungan</th>
			</tr>
			<tr>
				<th width="80">Laki-laki</th>
				<th width="80">Perempuan</th>
			</tr>
			<?php
				$row = mysql_num_rows($qry);
				if($row > 0){
					while($hasil = mysql_fetch_array($qry)){
						$tarif=get_hitung_klaim($hasil['id_klaim']);
						if($tarif['selisih'] >= 0){
							$lebih = $tarif['selisih'];
							$kurang = 0;
						}else {
							$kurang = str_replace("-","",$tarif['selisih']);
							$lebih = 0;
						}
						$no++;
				?>
						<tr>
							<td align="center"><?php echo $no ?></td>
							<td align="center"><?php echo $hasil['icd10']; ?></td>
							<td><?php echo $hasil['nama']; ?></td>
							<td align="center">
								<?php 
									$lk = mysql_num_rows(mysql_query("select pn.id_penduduk from klaim kl inner join klaim_diagnosis kd on kl.id_klaim = kd.id_klaim inner join peserta p on kl.id_peserta = p.id_peserta INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk INNER JOIN keluarga k ON k.id_kk = pn.id_kk inner join desa d on k.id_desa = d.id_desa inner join kecamatan kc on d.id_kecamatan = kc.id_kecamatan inner join kabupaten kb on kc.id_kabupaten = kb.id_kabupaten inner join jenis_layanan jl on jl.id_jenis_layanan = kl.id_jenis_layanan where kd.icd10 = '$hasil[icd10]' and kb.aktif = 'Y' and jl.kode = '1' and pn.jk = 'L' $tgl1 $tgl2 $dt_rs $dt_krj $dt_wlyh $q_usia1 $q_usia2 $dt_agama $dt_status $dt_ds group by id_penduduk"));
									echo $lk;
								?>
							</td>
							<td align="center">
								<?php 
									$pr = mysql_num_rows(mysql_query("select pn.id_penduduk from klaim kl inner join klaim_diagnosis kd on kl.id_klaim = kd.id_klaim inner join peserta p on kl.id_peserta = p.id_peserta INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk INNER JOIN keluarga k ON k.id_kk = pn.id_kk inner join desa d on k.id_desa = d.id_desa inner join kecamatan kc on d.id_kecamatan = kc.id_kecamatan inner join kabupaten kb on kc.id_kabupaten = kb.id_kabupaten inner join jenis_layanan jl on jl.id_jenis_layanan = kl.id_jenis_layanan where kd.icd10 = '$hasil[icd10]' and kb.aktif = 'Y' and jl.kode = '1' and pn.jk = 'P' $tgl1 $tgl2 $dt_rs $dt_krj $dt_wlyh $q_usia1 $q_usia2 $dt_agama $dt_status $dt_ds group by id_penduduk"));
									echo $pr;
								?>
							</td>
							<td align="center">
								<?php 
									$total = mysql_num_rows(mysql_query("select pn.id_penduduk from klaim kl inner join klaim_diagnosis kd on kl.id_klaim = kd.id_klaim inner join peserta p on kl.id_peserta = p.id_peserta INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk INNER JOIN keluarga k ON k.id_kk = pn.id_kk inner join desa d on k.id_desa = d.id_desa inner join kecamatan kc on d.id_kecamatan = kc.id_kecamatan inner join kabupaten kb on kc.id_kabupaten = kb.id_kabupaten inner join jenis_layanan jl on jl.id_jenis_layanan = kl.id_jenis_layanan where kd.icd10 = '$hasil[icd10]' and kb.aktif = 'Y' and jl.kode = '1' $tgl1 $tgl2 $dt_rs $dt_krj $dt_wlyh $q_usia1 $q_usia2 $dt_agama $dt_status $dt_ds group by id_penduduk"));
									echo $total;
								?>
							</td>
							<td align="center">
								<?php 
									$kunjungan = mysql_num_rows(mysql_query("select kl.id_klaim from klaim kl inner join klaim_diagnosis kd on kl.id_klaim = kd.id_klaim inner join peserta p on kl.id_peserta = p.id_peserta INNER JOIN penduduk pn ON p.id_penduduk = pn.id_penduduk INNER JOIN keluarga k ON k.id_kk = pn.id_kk inner join desa d on k.id_desa = d.id_desa inner join kecamatan kc on d.id_kecamatan = kc.id_kecamatan inner join kabupaten kb on kc.id_kabupaten = kb.id_kabupaten inner join jenis_layanan jl on jl.id_jenis_layanan = kl.id_jenis_layanan where kd.icd10 = '$hasil[icd10]' and kb.aktif = 'Y' and jl.kode = '1' $tgl1 $tgl2 $dt_rs $dt_krj $dt_wlyh $q_usia1 $q_usia2 $dt_agama $dt_status $dt_ds"));
									echo $kunjungan;
								?>
							</td>
						</tr>
			<?php	
					}
				}else{
				echo "<tr>
						<td align=center colspan=7>Data tidak Ada.</td>
					</tr>";
				}
			?>
		</table>
		</div>
	<?php
	}
	?>
